package com.manager.seat.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @ClassName DateUtils
 * @Description TODO
 * @date 2022/3/7 16:52
 * @Version 1.0
 */
public class DateUtils {

    public static final String pattern = "yyyy-MM-dd HH:mm:ss";
    public static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);

    public static final String pattern_day = "yyyy-MM-dd";
    public static final DateTimeFormatter dateTimeFormatter_Day = DateTimeFormatter.ofPattern(pattern_day);


    public static Date formatDate(String dateTime, String pattern) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.parse(dateTime);
    }

    public static String dateStr(long mill) {
        Date date = new Date(mill);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        return simpleDateFormat.format(date);
    }

    /**
     * 获取 LocalTime
     */
    public static LocalTime localTime() {
        return localDateTime().toLocalTime();
    }

    /**
     * 获取 LocalDateTime
     */
    public static LocalDateTime localDateTime() {
        return LocalDateTime.now();
    }

    /**
     * 获取指定时间格式的 LocalDateTime
     * yyyy-MM-dd HH:mm:ss
     */
    public static LocalTime parse(String dateTimeStr) {
        return LocalDateTime.parse(dateTimeStr, dateTimeFormatter).toLocalTime();
    }

    /**
     * 获取 LocalDate 天数,不包括时分秒
     * 当天如2020-10-31
     */
    static LocalDate localDate() {
        return localDateTime().toLocalDate();
    }

    public static String getCurrentTime() {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate localDate = LocalDate.now();
        String format = dateTimeFormatter.format(localDate);
        // 2022/06/02
        System.out.println(format);
        return format;
    }

    /**
     * 获取当天 8:15 的时间
     *
     * @return
     */
    public static LocalDateTime getSpecTime8_15() {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate localDate = LocalDate.now();
        String str = dateTimeFormatter.format(localDate);
        String str1 = str + " 08:15:00";

        LocalDateTime localTime = LocalDateTime.parse(str1,DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        // 2022/06/02
        return localTime;
    }
    /**
     * 获取当天 8:15 的时间
     *
     * @return
     */
    public static LocalDateTime getSpecTime7_55() {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate localDate = LocalDate.now();
        String str = dateTimeFormatter.format(localDate);
        String str1 = str + " 07:55:00";

        LocalDateTime localTime = LocalDateTime.parse(str1,DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        // 2022/06/02
        return localTime;
    }

    /**
     * 比较两个时间
     * date1>date2 返回-1 date1 比date2晚
     * date1= date2 返回0
     * date1<date2 返回 1
     *
     * @param date1 第一个时间
     * @param date2 第二个时间
     * @return 结果
     */
    public static int compare(LocalDateTime date1, LocalDateTime date2) {
        return date1.compareTo(date2);
    }


}
